package com.example.userserver.manager;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.userserver.entity.CityInfo;
import com.example.userserver.mapper.CityInfoMapper;
import com.example.userserver.params.PageCityInfoParams;
import com.example.userserver.utils.BeanCopyUtils;
import com.example.userserver.vo.CityInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class CityInfoManager {
    @Autowired
    private CityInfoMapper citylnfoMapper;

    public void insertCityInfo(CityInfo cityInfo){
        citylnfoMapper.insert(cityInfo);
    }

    public void deleteCityInfo(String id){
        citylnfoMapper.deleteById(id);
    }

    public void updateCityInfo(CityInfo cityInfo){
        citylnfoMapper.updateById(cityInfo);
    }

    public List<CityInfoVO> listCityInfo(PageCityInfoParams pageCityInfoParams){
        QueryWrapper queryWrapper = new QueryWrapper();
        if( ! StringUtils.isEmpty(pageCityInfoParams.getCityName())) {
            queryWrapper.like("city_name", pageCityInfoParams.getCityName());
        }
        return citylnfoMapper.selectList(queryWrapper);
    }

    public CityInfoVO getCityInfo(String id){
        CityInfo cityInfo = citylnfoMapper.selectById(id);
        CityInfoVO cityInfoVO = new CityInfoVO();
        BeanCopyUtils.copyPropertiesIgnoreNull(cityInfo, cityInfoVO);
        return cityInfoVO;
    }
    public CityInfo selectCity(QueryWrapper queryWrapper){
        CityInfo cityInfo = citylnfoMapper.selectOne(queryWrapper);
        return cityInfo;
    }
}
